Tutorials
This documentation goes over how to use Smart Curriculum Designer, the machine learning and AI curriculum generator. The application itself enables educators to generate models, content, exercises, and solutions, weaving the domain/dataset specified by the educator.
Getting Started
This application uses Tapis, if you already have an account and a system authenticated you may skip this section.
- Navigate to https://icicleai.tapis.io/#/login. You will be prompted to login. Please select University Accounts (CILogon). If you do not have an Access account, you can create one here: https://account.access-ci.org/register

- Select the University that you are affiliated with to log in.

- After logging in you will be shown the main page for Icicle’s TAPIS.

-
To use this application, a system needs to be authenticated. We’ll use SDSC’s Expanse portal for this demonstration: https://portal.expanse.sdsc.edu/
- You may log in using the ACCESS/CILogon account created beforehand.
-
Once logged in, click on expanse Shell Access.

-
Inside the terminal, you will need to run these commands:
ssh-keygen -t rsa -b 4096 -m PEM
cd ~/.ssh
cat id_rsa.pub
cat id_rsa
echo 'export SCRATCH="/expanse/scratch/${USER}"' >> ~/.bashrc
echo 'export SCRATCH="/expanse/scratch/${USER}"' >> ~/.bash_profileid_rsa.pubis your public key andid_rsais your private key. We will be using these to authenticate the Expanse system.In the terminal, run
cd ~/.sshandnano authorized_keysand paste the contents of your public key in. RunCTRL + Xto save the contents of the file.


- Log back into https://icicleai.tapis.io/ and click on Systems.

- Click on the Authenticate button. The screen below will appear. Paste in your credentials generated from the keys made earlier into Private key and Public key and enter your username for that system in Login User.


- Your account should be authenticated now and should show this screen:

Common Issues
- Double check that the entire public/private key is pasted into the box, including keys that may start with “----------- BEGIN RSA KEY —------------”. It's important to paste that in as well.
- Ensure in
authorized_keysyour public key is pasted in and saved. - Ensure that the system you’re attempting to authenticate is the same system your authorized keys reside in.
Prerequisites
Please refer to the YAML Configuration Guide. This documentation is important as it goes over one of the key inputs for this application to run correctly.
Additionally, as noted in the YAML Configuration Guide, the application expects a specific dataset structure to run as expected. The program recursively takes each folder inside the directory as a label. For example:
food/
|_pasta/
|_pizza/
|_pepperoni_pizza/
|_etc./
Pasta, pizza, pepperoni_pizza, and any other folder name will be taken as a label for the program. Images within its parent folder will be labeled as the parent folder’s name.
If you do not have a dataset, consider looking for one on Kaggle and please also refer to using KaggleHub for downloading the dataset into a directory.
Uploading to a System
This section demonstrates the steps to uploading the YAML configuration to a system.
- Navigate to https://portal.expanse.sdsc.edu/
- Under Files, click Home Directory.

- Click on Upload and here you may upload the configuration you created.




- The path to your configuration file can be found by clicking the Copy Path button, pasting that output, and appending “/{your config name}”.
- For example:
/home/jseh/expanse/test_config.yaml
- For example:
- Remember/Write down this file path.
Running the Application
- Navigate to https://icicleai.tapis.io/
- Under Tapis Services click on Apps.
- From the sidebar, scroll down and click on digital-age-edu.

- Click Submit Job. Afterwards click USE GUIDED JOB LAUNCHER.


- This will pull up the Guided Job Launcher. This will be the main interface we use to start the application. Click Continue.

- This is the Execution Options page. These determine the System the program will run on alongside the directory the program will run in.
- Under Execution System select
expanse-tapis-static(default). - Under Batch Logical Queue select
tapisGPUshared. - Under Execution System Execution Directory, Execution System Input Directory, and Execution System Output Directory, write down the path you want the application to run on. Append a “/${JobUUID}” to the end.
- Remember/Write this down somewhere. Make sure it is a path on that system and a valid path on your account. For example:
/home/<your_username>/${JobUUID}.
- Under Execution System select


- Click Continue until you reach Arguments. This section includes application arguments. We will be inputting the configuration created earlier. If you didn’t yet do so please refer back to Prerequisites.
- Inside Value paste in the absolute path to the YAML configuration you created, for example mine would be:
/home/jseh/expanse/test_config.yaml.
- Inside Value paste in the absolute path to the YAML configuration you created, for example mine would be:

- Click Continue until you reach Scheduler Options. In this section you define the id of your project to charge for usage.
- By default, the community allocation
-A uot260is pre-filled so users do not need their own individual project account set up. If you have your own allocation, you may specify-A {Your Project ID}(found at https://portal.expanse.sdsc.edu/pun/sys/stats).
- By default, the community allocation

- Click Continue until you reach the Job Submission page.
- Click Submit Job.
- Keep note of the job id. In this example it is
d15d50c5-794…….. - Navigate back to the main page and click on Jobs.
- Here you can see the job has been queued into Tapis. It will take some time for the application to run.
- Please note to see any program text outputs it will be within
tapisjob.outand you will need to reload the page to see current updates on the job status.



Understanding the Outputs
[!WARNING]
Critical Advisory: Download Results to Your Local Device
Expanse Static (
expanse-tapis-static) is a community-managed execution system. File storage within shared and temporary scratch/job directories on Expanse Static is subject to periodic maintenance and may be wiped or cleared for storage management reasons.Always download your generated outputs (curriculum markdown, exercises, reference solutions, metrics, plots, and models) to your local device or permanent institutional storage immediately after the job finishes.
The application is done running once in Jobs you see this:

Outputs
This section details the outputs of the program, how to use them, and overall expectations for after it runs.
-
models/- A
.pthwith weights to the trained DINOv2 model for classification sam_vit_b_.pthweights for segmentation
- A
-
{the output directory name defined in the config}/results.json: Overall metrics for the pipeline and training/inferenceclass_mapping.json: Indexes the classes found to a numberconfusion_matrix.png: Confusion matrix compiled from each foldeval_confusion_matrix.png: Final model confusion matrix across entire datasetcurriculum.json: A json file for the curriculumcurriculum_{grade_level}.md: A markdown variant of the curriculumcv_report.json: Model performance per foldresults.csv: The CSV containing metadata and data for every image
-
{the output directory name defined in the config}/exercises:Week_{xx}/Module/concepts.md: markdown containing concepts needed for the given module{concept}_exercise.py: The exercise for the student to complete. These are meant to be incomplete when generated so will fail when first ran{concept}_solution.py: The solution to the exercise{concept}_test.py: The test cases for the student to useresources.md: Markdown containing resources for the module
-
{the output directory name defined in the config}/imagesmasks/: The mask used for segmentationsegmented/: The segmented image
Downloading Outputs to Your Local Machine
Because Expanse Static is community-managed and files may be purged over time, use the following methods to transfer the generated files to your personal computer:
- Navigate to the Expanse Web Portal: https://portal.expanse.sdsc.edu/
- In the top navigation bar, click Files -> Home Directory (or navigate to your scratch/execution directory).
- Browse to your job's execution directory and enter the
outputfolder. - Select the generated curriculum folder or archive and click Download in the upper action menu.
Accessing and Running Exercises on the System
This section goes over how to inspect and run the generated exercises directly on the cluster before or alongside downloading them.
- Log into your system at https://portal.expanse.sdsc.edu/
- Click on expanse Shell Access.
- Inside the terminal execute the command:
For example mine is:
cd {the execution directory you saved, replacing ${JobUUID} with the job id}cd /home/jseh/scratch/jobs/5ce7ce30-50d0-47d1-91be-220c7e4ea26c-007 - Execute
ls. This will list the subdirectories within that directory. - Execute
cd output. This changes your current directory into output. - Execute
cd {what you named the directory}. Ex: my command iscd skin_cancer_v1. - Execute
cd exercises. Here you will see the different modules. - For now we will go back to install the requirements. Run
cd ../to change directory into the parent folder.- Run
module load cpu/0.21.2a gcc/13.3.0/t46rsdv - Run
module load python/3.11.9/je56t6b
- Run
- Run
python -m venv venv. This will install the python virtual environment into the directory. - After it’s done installing run
source venv/bin/activate. - Execute
pip install uv. - Execute
uv pip install -r requirements.txt. This will install all the requirement in parallel. - Execute
cd exercisesto get back into the exercises, runls, and cd into a week. - You may run
nano {the exercise name}_exercise.pyto edit the contents of that week. Saving the contents, you can runpython {the file name}to run the code within the file.

YAML Configuration Guide
Smart Curriculum Designer expects a YAML configuration to run correctly. This acts as the main point of freedom for educators to determine the content for their curriculum. Each parameter outlined here serves a purpose and unless otherwise specified needs to be filled out. Please refer to the sample YAML configuration listed below this document and on the line below. Additionally, please read the section Uploading to a System upon creating your config file.
A sample YAML configuration can be found here.
Implemented Parameters
Project
domain: This is used by the VLM to define its background expertise.context_statement: A description of the problem. This is used by the automated curriculum generator to construct course topics, and by the VLM to structure its answers.use_case: Reserved for future extension. Changing this does not affect execution.
Dataset
root_path: The absolute or relative path to the directory containing your images. Ensure the subfolders of the main directory are named the classes of the images. Eg:food/
|_pasta/
|_pizza/
|_etc./
Output
output: Configurations for the outputdirectory: The destination folder where model predictions (results.csv), segmentation images, and execution logs will be written.
Pipeline
stages: Sequential stages the pipeline will run. The stages run as such: Classification (DINOv2) -> Segmentation (SAM) -> VisualXAI (Grad-CAM)active: Toggles whether this stage runs. If set to false, the pipeline skips this model completely.prompt: Text inputs used for visual grounding:- For Segmentation: The text prompt describing the object to isolate (e.g., "the leaf", "the skin lesion").
Execution
device: Set to"cuda"for fast GPU processing on machines with NVIDIA cards (or OSC cluster nodes). Set to"cpu"for slower, localized execution.batch_size: The number of images loaded into GPU memory at once. If you hit out-of-memory (OOM) errors, lower this value (e.g. from 16 to 4).image_size: Square resolution to resize input images. (518 is heavily recommended)max_samples: Set to a number (e.g. 20) to quickly test the pipeline on a small subset. Set to null to run over the entire dataset.seed: An integer locking randomness across Python, NumPy, and PyTorch, ensuring your cross-validation split and weight initialization remain 100% reproducible.
Curriculum
subject&grade: Meta details printed on the generated lesson documents.weeks: Optional curriculum length. If omitted, the program will sum the weeks of the modules, or default to the amount of weeks for each module ifmodules.weeksis omitted too.modules:id: The id of the module. Refer to the YAML sample for a full list of every moduleweek: The week the module will reside in. One week can have multiple modules.
topics: Custom descriptions representing the core projects students will work on.name: The name of the topic.description: The description for the topic.project: The project the topic is under.
resources: Attaching resources relevant to the curriculum.name: Name for the documentation.url: URL leading to the documentation.
Uploading to a System
This section demonstrates the steps to uploading the YAML configuration to a system.
- Navigate to https://portal.expanse.sdsc.edu/
- Under Files, click Home Directory.

- Click on Upload and here you may upload the configuration you created.




- The path to your configuration file can be found by clicking the Copy Path button, pasting that output, and appending “/{your config name}”.
- For example:
/home/jseh/expanse/test_config.yaml
- For example:
- Remember/Write down this file path.
Sample YAML Config
# ==============================================================================
# BOILERPLATE CONFIGURATION FOR SMART CURRICULUM DESIGNER
# Instructions: Use this template for deploying new datasets on Tapis/OSC.
# Ensure all model_paths and dataset_roots point to PERSISTENT SHARED STORAGE
# ==============================================================================
# ===============
# Project Context
# ===============
project:
domain: "<INSERT_DOMAIN> (e.g., Medical Imaging, Precision Agriculture)"
context_statement: "<INSERT_CONTEXT> (e.g., diagnosing leaf diseases from images)"
use_case: "educational_curriculum"
# ================
# Dataset Settings
# ================
dataset:
# IMPORTANT NOTE: Point this to a persistent storage path
root_path: "/path/to/shared/persistent/storage/dataset_folder"
output:
# Output directory where results will be generated
directory: "./outputs/experiment_v1"
# ================
# Pipeline Stages
# ================
pipeline:
stages:
- name: "Classification"
active: true
task_type: "<INSERT_TASK_TYPE>"
- name: "Segmentation"
active: true
task_type: "object_extraction"
prompt: "<INSERT_TARGET_OBJECT> (e.g., the skin lesion, the diseased leaf)"
- name: "VisualXAI"
active: false # Explainable AI / Attention Maps
task_type: "visual_explainability"
# ============
# Execution
# ============
execution:
device: "cuda" # Required for DINOv2 performance
batch_size: 16
image_size: 518
max_samples: null # Set to an integer (e.g., 50), null for full dataset
seed: 42
# ==================
# Curriculum Config
# ==================
curriculum:
subject: "<INSERT_COURSE_SUBJECT>"
grade: 10
weeks: 24
modules:
# Explicit per-week assignments (multiple modules can share the same week)
- id: "numpy_basics"
week: 1
- id: "pandas_analytics"
week: 1
- id: "pytorch_basics"
week: 2
- id: "interactive_segmentation"
week: 3
- id: "image_datasets"
week: 4
- id: "custom_cnn"
week: 4
- id: "cnn_optimization"
week: 4
- id: "transfer_learning"
week: 4
- id: "semantic_segmentation"
week: 4
- id: "explainable_ai"
week: 5
- id: "vector_embeddings"
week: 5
- id: "gradio_deployment"
week: 6
topics:
- name: "<INSERT_TOPIC_NAME>"
description: "<INSERT_TOPIC_DESCRIPTION>"
project: "<INSERT_PROJECT_NAME>"
resources:
- name: "Dataset Source"
url: "<INSERT_DATASET_URL>"
Curriculum Modules & Concepts Guide
This guide provides a comprehensive overview of the curriculum modules generated by Smart Curriculum Designer. It details the pedagogical goals, mathematical foundations, core programming exercises, and learning outcomes for each topic across the computer vision and machine learning curriculum.
Table of Contents
- Module 1: NumPy Array Basics, Vectorization & Performance
- Module 2: Pandas Data Wrangling & Matplotlib Visualizations
- Module 3: PyTorch Foundations & Neural Network Lifecycle
- Module 4: Interactive Image Segmentation with OpenCV
- Module 5: Custom PyTorch Datasets, Transforms & DataLoaders
- Module 6: Custom Convolutional Neural Networks (CNNs)
- Module 7: CNN Optimization, Regularization & Checkpoints
- Module 8: Transfer Learning & Backbone Benchmarking
- Module 9: Semantic Segmentation & Dense U-Net Decoders
- Module 10: Explainable AI & Grad-CAM Attributions
- Module 11: Image Embeddings, PCA Clustering & Vector Search
- Module 12: Capstone Integration & Gradio Deployment
- Module 13: Vision-Language Models (VLM) & Multimodal VQA
- Supplementary Student & Instructor Deliverables
Module 1: NumPy Array Basics, Vectorization & Performance
Pedagogical Goal
Establishes that in computer vision, images are 3D numerical matrices of shape $(H, W, C)$. Students master fast, hardware-accelerated matrix operations and learn to avoid slow Python for loops when handling high-resolution visual data.
Core Concepts & Mathematics
- Multidimensional Arrays (Ndarrays): Memory-contiguous pixel grids for fast CPU hardware retrieval.
- Z-Score Normalization: $$\mu = \frac{1}{N} \sum x_i, \quad \sigma = \sqrt{\frac{1}{N} \sum (x_i - \mu)^2}, \quad Z_i = \frac{x_i - \mu}{\sigma}$$ Standardizes input distributions to prevent early gradient scaling anomalies during neural network training.
- Broadcasting: Performing arithmetic operations on arrays of mismatched shapes without copying memory (e.g., subtracting a $(3,)$ channel mean vector from a $(224, 224, 3)$ image).
- SIMD Vectorization: Replacing interpreter loops with compiled C-level Single Instruction, Multiple Data operations.
Key Functions & Student Exercises
create_and_reshape_arrays(): Creates 1D numerical sequences and reshapes them into 2D matrices, zero arrays, and ones arrays.slice_and_crop(mock_image): Extracts bounding regions of interest using coordinate slicing[y_start:y_end, x_start:x_end, :].apply_broadcasting(image, mean_vector, mask): Normalizes pixel values to $[0.0, 1.0]$, centers by channel mean, and applies a 2D spatial binary mask.elementwise_math(arr): Vectorized squaring, linear shifting, and bounds restriction usingnp.clip.statistics_and_standardization(arr): Extracts global mean, standard deviation, min, max, and handles divide-by-zero variance cases.boolean_thresholding(image, threshold): Creates boolean masks for pixel filtering.matrix_multiplication(w, x): Transposition and matrix dot-product operations using the@operator.loop_vs_vectorization_benchmark(size): Performance benchmark measuring execution speedup of NumPy vectorization over pure Python loops.- Bonus Challenge —
extract_patches(image, patch_size, stride): Slices large high-resolution images into uniform spatial tiles (essential for gigapixel pathology and satellite scans).
Module 2: Pandas Data Wrangling & Matplotlib Visualizations
Pedagogical Goal
Teaches students how to inspect model prediction logs (results.csv), extract error patterns, and conduct active learning error audits to identify model blind spots and prioritize dataset re-annotation.
Core Concepts & Mathematics
- Classification Accuracy Metric: $$\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}$$
- Error Mining & Active Learning: Sorting prediction logs by confidence to isolate high-confidence incorrect predictions ("hard negatives") for targeted data re-collection.
- Data Hygiene: Handling missing values (NaNs) safely without introducing statistical data leakage between training and validation distributions.
Key Functions & Student Exercises
explore_and_inspect_data(csv_path): Loads tabular CSV logs, inspecting structure via.head(),.tail(),.info(), and.describe().select_and_filter_data(df): Slices columns and isolates misclassified samples wherepredicted_class != ground_truth.feature_engineering(df): Creates boolean flagsis_correctand categorical error descriptionserror_type.sort_and_find_extremes(df): Sorts samples to identify extreme failure modes.group_statistics(df): Performsgroupby("ground_truth")aggregations to measure per-class sample counts and precision rates.handle_missing_values(df): Cleans corrupted logs via.fillna()and.dropna().create_matplotlib_visualizations(df, plot_dir): Generates multi-panel figures:- Training vs. validation loss curve comparisons.
- Per-class classification accuracy bar charts.
- Misclassification distribution histograms.
- Overall correctness pie charts.
- Bonus Challenge —
find_hardest_samples(df, class_name, top_n): Mines the top $K$ worst mistakes for a specific class to prioritize dataset re-annotation.
Module 3: PyTorch Foundations & Neural Network Lifecycle
Pedagogical Goal
Demystifies neural network internals. Students build a Multi-Layer Perceptron (MLP) from scratch in PyTorch, trace Autograd gradient graphs, and write the complete training and validation lifecycle.
Core Concepts & Mathematics
- Binary & Multi-Class Cross-Entropy Loss: $$L_{BCE} = -\frac{1}{N} \sum_{i=1}^N \left[ y_i \log(p_i) + (1 - y_i) \log(1 - p_i) \right]$$
- Softmax Probability Mapping: $$P(y = c \mid z) = \frac{e^{z_c}}{\sum_{j=1}^C e^{z_j}}$$
- Autograd & The Training Lifecycle Step:
optimizer.zero_grad()$\to$ Reset accumulated gradients.outputs = model(inputs)$\to$ Forward pass.loss = criterion(outputs, targets)$\to$ Compute objective penalty.loss.backward()$\to$ Compute exact parameter gradients via the chain rule.optimizer.step()$\to$ Update weights using gradient descent.
Key Functions & Student Exercises
tensor_basics(python_list): Converts Python lists to float tensors, generates normal distributions, and handles GPU (cuda) device mapping.compute_autograd_gradient(x_value): Defines scalar functions on leaf tensors withrequires_grad=Trueand computes analytic derivatives.SimpleImageMLP: Inherits fromnn.Module, definingnn.Linearlayers,nn.ReLUactivations, and flattening $(B, C, H, W)$ tensors to $(B, C \cdot H \cdot W)$.inspect_forward_shapes(model, x): Traces spatial dimension contraction through intermediate layers.count_trainable_parameters(model): Calculates total parameters wherep.requires_grad == True.logits_to_probabilities(logits): Converts unbounded decision logits into probability vectors usingtorch.softmaxandtorch.argmax.train_step()&validation_step(): Implements isolated training and validation execution modes (model.train()vsmodel.eval()withtorch.no_grad()).calculate_accuracy_manually()&calculate_confusion_matrix_manually(): Builds $C \times C$ confusion matrices directly using tensor comparison logic.train_model(): Complete multi-epoch training orchestrator featuring index shuffling, batch iterations, validation tracking, and.pthweight saving.- Bonus Challenge —
train_step_with_l2(model, ..., l2_lambda): Manually calculates and injects an L2 weight decay penalty ($\frac{\lambda}{2}\sum w^2$) into the loss before backpropagation.
Module 4: Interactive Image Segmentation with OpenCV
Pedagogical Goal
Contrasts classical computer vision heuristics (seed-based FloodFill) with deep learning foundation models (Segment Anything / SAM), providing an interactive GUI to explore pixel connectivity.
Core Concepts & Mathematics
- Spatial Image Moments & Centroids: $$M_{ij} = \sum_{x,y} x^i y^j I(x,y), \quad cX = \frac{M_{10}}{M_{00}}, \quad cY = \frac{M_{01}}{M_{00}}$$
- Intersection over Union (IoU / Jaccard Index): $$\text{IoU}(A, B) = \frac{|A \cap B|}{|A \cup B|}$$
- Breadth-First Search (BFS) FloodFill: Propagating mask boundaries based on color differences (
loDiff/upDiff) vs. deep semantic feature attention in SAM.
Key Functions & Student Exercises
inspect_image(image): Retrieves height, width, dtype, and color channels.convert_color_spaces(image): Converts BGR arrays into display RGB, luminance Grayscale, and color-filtering HSV.threshold_image(image, threshold_value): Applies binary intensity thresholding.floodfill_segmentation(image, seed_point, tolerance): Applies seed-point FloodFill with border padding.calculate_iou(mask_a, mask_b): Computes spatial overlap similarity between classical masks and pipeline SAM masks.create_overlay(image, mask, color, alpha): Blends color masks onto images viacv2.addWeighted.find_and_draw_contours()&get_bounding_box(): Computes outer contour vectors and minimum bounding rectangles $(x, y, w, h)$.- Interactive GUI / Headless Fallback: Real-time OpenCV window listening to mouse clicks, tolerance adjustment keys (
+/-), and generating side-by-side comparison overlays against SAM. - Bonus Challenge —
calculate_mask_centroid(mask): Uses spatial moments (cv2.moments) to locate the center-of-mass coordinates of segmented regions.
Module 5: Custom PyTorch Datasets, Transforms & DataLoaders
Pedagogical Goal
Teaches scalable, memory-efficient data engineering for computer vision on supercomputers. Students implement custom Dataset classes using on-the-fly lazy loading to avoid RAM exhaustion.
Core Concepts & Mathematics
- Dataset-Wide Channel Normalization: $$\mu_c = \frac{1}{N \cdot H \cdot W} \sum_{i=1}^N \sum_{y=1}^H \sum_{x=1}^W I_c(i, y, x)$$
- Pipeline Shape Transitions: $$\text{PIL Image }(H, W, C) \xrightarrow{\text{ToTensor}} \text{Tensor }(C, H, W) \xrightarrow{\text{DataLoader}} \text{Batch }(B, C, H, W)$$
- Data Augmentation: Preserving semantic labels while introducing geometric perturbations (random flips, rotations) on training sets, while keeping validation sets strictly deterministic.
Key Functions & Student Exercises
split_dataset(image_paths, train_ratio, seed): Generates reproducible train/test splits.CustomImageDataset: Inherits fromtorch.utils.data.Dataset, implementing:__len__: Returns total valid image file paths (filtering OS artifacts like.DS_Store).__getitem__: Dynamically opens images via PIL, extracts directory class labels, applies transforms, and returns(tensor, label).
build_transforms()&build_augmentation_transforms(): Constructstransforms.Composepipelines with resizing, horizontal flips, rotations, tensor casting, and ImageNet standardization.inspect_transform_flow(): Traces structural dimension changes at each preprocessing step.calculate_dataset_statistics(): Scans directory hierarchies to identify class distribution imbalances.validate_batch(): Sanity-checks batches for NaNs, 4D shape validity, float32 dtypes, and label index ranges.visualize_batch(): Un-normalizes tensors and plots $4 \times 4$ image grids with class titles.compare_shuffle_effect(): Demonstrates howshuffle=Truebreaks class ordering biases across training epochs.- Bonus Challenge —
calculate_dataset_stats(dataset, max_samples): Computes dataset-specific channel mean and standard deviation vectors across all images.
Module 6: Custom Convolutional Neural Networks (CNNs)
Pedagogical Goal
Transitions students from MLPs to Convolutional Neural Networks. Explains how sliding kernel filters preserve spatial locality and reduce parameters through weight sharing.
Core Concepts & Mathematics
- Convolutional Output Dimension Arithmetic: $$O = \left\lfloor \frac{I - K + 2P}{S} \right\rfloor + 1$$
- Learnable Parameter Count for Conv Layers: $$\text{Params} = C_{out} \cdot (C_{in} \cdot K^2 + 1)$$
- Receptive Field Expansion: How stacking small $3 \times 3$ filters and pooling layers expands the effective visual area captured by deeper neurons.
Key Functions & Student Exercises
CustomCNN: Constructs a 2-stage CNN architecture containingnn.Conv2d(3 $\to$ 8),nn.MaxPool2d(2, 2),nn.Conv2d(8 $\to$ 16),nn.MaxPool2d(2, 2), and a linear classification head.count_parameters(model): Calculates total learnable parameters.trace_cnn_shapes(model, sample_tensor): Records tensor dimension changes through convolution, activation, pooling, and flattening layers.extract_first_layer_activations(): Intercepts and extracts early feature map activations.visualize_pooling_effect(): Plots feature maps before and after max-pooling side-by-side to visualize spatial compression.visualize_feature_maps(): Renders a $2 \times 4$ grid showing the input image alongside its first 7 convolutional filter responses (initialized with Sobel and Laplacian edge filters).softmax_predictions(): Maps raw network logits to percentage probabilities.- Bonus Challenge —
cnn_block_analysis(input_height, input_width): Calculates final output activation shapes, combined parameter counts, and raw memory footprint in bytes.
Module 7: CNN Optimization, Regularization & Checkpoints
Pedagogical Goal
Teaches techniques for stabilizing model training on supercomputers, combating overfitting, and creating resilient validation checkpoint pipelines.
Core Concepts & Mathematics
- Step Learning Rate Decay: $$\eta_t = \eta_0 \cdot \gamma^{\lfloor t / s \rfloor}$$
- Batch Normalization (
BatchNorm2d): Standardizing batch activations to accelerate convergence and reduce sensitivity to initialization. - Dropout Regularization: Randomly zeroing neuron activations during training to force redundant feature representations.
Key Functions & Student Exercises
RegularizedCNN: Implements a CNN with toggles forBatchNorm2dandDropoutacross stages.optimize_model_hyperparameters(): Configures an Adam optimizer with L2 weight decay and aStepLRscheduler.validation_checkpoint_step(): Monitors validation loss, serializing.pthstate dictionaries when performance reaches a new minimum.compare_baseline_vs_optimized(): Runs side-by-side training comparing unregularized baseline models against regularized networks over 15 epochs.plot_weight_distributions(): Plots histograms of convolutional weights to show how regularization prevents extreme weight spikes.simulate_checkpointing_story(): Terminal simulation demonstrating how checkpoints restore the best model state after overfitting occurs.- Bonus Challenge —
audit_checkpoint_integrity(model, checkpoint_path, ...): Audits saved.pthcheckpoint files for shape mismatches, key completeness, and optimizer/scheduler state consistency before loading.
Module 8: Transfer Learning & Backbone Benchmarking
Pedagogical Goal
Explains why foundation vision models achieve high accuracy on small datasets. Students configure layer freezing, fine-tune ResNet architectures, and benchmark predictions against DINOv2 pipeline outputs.
Core Concepts & Mathematics
- Hierarchical Visual Primitives: Early layers detect universal edges and shapes; late layers detect domain-specific semantics.
- Cosine Proximity in Feature Space: $$\text{Cosine}(A, B) = \frac{A \cdot B}{|A| \cdot |B|}$$
- Freezing vs. Discriminative Fine-Tuning: Locking early feature extractors (
requires_grad = False) vs. unfreezing high-level residual blocks (layer4).
Key Functions & Student Exercises
get_resnet_model(num_classes, mode): Configures ResNet18 in"frozen"(head only) or"unfrozen_last_block"modes.count_trainable_parameters(): Compares trainable parameter counts (thousands vs. millions).visualize_feature_reuse(): Compares activations from randomly initialized filters against structured, pretrained ResNet filters on the same image.run_10_image_comparison(): Evaluates a 10-image slice, generating an audit table comparing DINOv2 vs. ResNet predictions and confidence scores.- Bonus Challenge —
classify_with_prototypes(query_embedding, class_prototypes): Implements a nearest class prototype classifier using Cosine Similarity for few-shot learning.
Module 9: Semantic Segmentation & Dense U-Net Decoders
Pedagogical Goal
Bridges classification and dense pixel-wise prediction. Students build a transposed-convolution decoder to rebuild spatial resolution from compressed bottleneck features.
Core Concepts & Mathematics
- Soft Dice Loss Optimization: $$L_{Dice} = 1 - \frac{2 \sum (p_i \cdot g_i) + \epsilon}{\sum p_i^2 + \sum g_i^2 + \epsilon}$$
- Combined Segmentation Loss: $$L_{\text{Total}} = L_{\text{BCEWithLogits}} + L_{\text{Dice}}$$
- Learned Upsampling & Skip Connections: Using
ConvTranspose2dto expand spatial dimensions while highlighting why skip connections are necessary to recover fine border contours.
Key Functions & Student Exercises
MiniSegmentationDecoder: Implements a multi-stage upsampler usingnn.ConvTranspose2d(kernel=4, stride=2, padding=1) with dimension validation assertions.compute_hard_dice(): Calculates the non-differentiable Dice Similarity Coefficient (DSC) on boolean thresholded masks.compute_soft_dice(): Computes the differentiable Soft Dice coefficient across spatial dimensions.combined_loss(): Implements a composite loss function combining BCE with logits and Soft Dice loss.find_optimal_threshold(): Searches candidate thresholds $[0.1, 0.9]$ to maximize the Jaccard/Dice overlap score against ground-truth SAM masks.
Module 10: Explainable AI & Grad-CAM Attributions
Pedagogical Goal
Teaches model transparency and auditability. Students use PyTorch hooks to capture gradients and feature maps, projecting visual heatmaps that show why a model made a specific prediction.
Core Concepts & Mathematics
- Grad-CAM Attribution Weighting: $$\alpha_c^k = \frac{1}{Z} \sum_{i,j} \frac{\partial Y^c}{\partial A_{i,j}^k}, \quad L_{\text{Grad-CAM}}^c = \text{ReLU}\left( \sum_k \alpha_c^k A^k \right)$$
- Attribution vs. Segmentation: Segmentation identifies what is present; attribution identifies what influenced the decision.
- Class Sensitivity & Cautions: Verifying that heatmaps change when switching target classes, and understanding failure modes (gradient saturation, spurious correlations).
Key Functions & Student Exercises
GradCAMHook: A Python context manager that registers and removes PyTorch forward and backward hooks on target convolutional layers.generate_gradcam(): Computes channel gradient weights, computes the weighted sum of feature maps, applies ReLU, and normalizes the heatmap to $[0.0, 1.0]$.generate_saliency_map(): Computes vanilla pixel-wise input gradients ($\max_c |\nabla_X Y^c|$).test_class_switch_stability(): Evaluates class sensitivity by generating heatmaps for Class A vs. Class B on the same image and computing their overlap IoU.- Bonus Challenge —
postprocess_heatmap(cam, threshold): Implements a $3 \times 3$ box-blur smoothing filter and threshold binarizer to clean attribution overlays. - Bonus Challenge —
compute_heatmap_overlap(heatmap1, heatmap2): Computes quantitative IoU overlap between two distinct heatmaps.
Module 11: Image Embeddings, PCA Clustering & Vector Search
Pedagogical Goal
Connects spatial feature maps to high-dimensional latent embeddings. Students implement vector similarity search and dimensionality reduction for clustering analysis.
Core Concepts & Mathematics
- Cosine Similarity (Angular Alignment): $$\text{Cosine}(A, B) = \frac{A \cdot B}{|A| \cdot |B|}$$
- Magnitude Invariance: Why Cosine Similarity ignores vector length (intensity/brightness) to focus purely on semantic direction.
- PCA Dimensionality Reduction: Projecting high-dimensional representations to 2D for visual inspection while querying full-dimensional vectors in production search.
Key Functions & Student Exercises
compute_cosine_similarity(vec_a, vec_b): Computes angular alignment between 1D representation vectors.project_to_2d(embeddings, n_components=2): Uses Principal Component Analysis (PCA) to compress high-dimensional vectors to 2D coordinates.semantic_search(query_embedding, database_embeddings, top_k): Performs cosine nearest-neighbor search across an image vector database.plot_embedding_clusters(): Renders color-coded 2D scatter plots of projected image clusters.- Bonus Challenge —
compute_euclidean_distance(vec_a, vec_b): Computes magnitude-sensitive Euclidean distance ($\sqrt{\sum (A_i - B_i)^2}$) to compare against Cosine metric behaviors.
Module 12: Capstone Integration & Gradio Deployment (Work In Progress)
Pedagogical Goal
The capstone integration module. Students combine their trained classification model, segmentation overlays, and explainability heatmaps into a full-stack interactive web application using Gradio.
Core Concepts & Workflows
- End-to-End Inference Pipelines: Wrapping preprocessing, forward prediction, FloodFill/SAM segmentation, and saliency map extraction into a unified execution handler.
- Client-Server ML Architectures: Exposing model capabilities through responsive UI components (image uploaders, confidence sliders, image overlays).
- Input Sanitation: Auditing user-uploaded images for corruption or flat variance before executing GPU passes.
Key Functions & Student Exercises
load_model_weights(model_path, num_classes): Instantiates models and safely loads serialized.pthstate dictionaries with fallback handling.segment_image_fallback(): Generates transparent green segmentation overlays.generate_saliency_map(): Generates pixel-wise attribution overlays for web rendering.run_pipeline(model, image_numpy, classes): Unified inference pipeline returning(predicted_class, confidence, segmentation_overlay, saliency_map).Gradio Web Interface Launch: Constructsgr.Interfacewith image upload inputs, prediction textboxes, confidence sliders, and dual visual diagnostic display panels.- Bonus Challenge —
get_image_pixel_statistics(image_numpy): Computes uploaded image pixel statistics (mean, std, min, max) to validate input quality.
Supplementary Student & Instructor Deliverables
Alongside the coding exercises, each module automatically generates supporting documentation:
1. concepts.md (Module Theoretical Guide)
Generated inside each weekly exercise folder to serve as an on-demand textbook chapter:
- Core Concepts: Detailed explanations of visual representations, layer architectures, and engineering principles.
- Mathematical Formulations: LaTeX equations, complete variable definitions, and machine learning rationale.
- Key Functions & Real-World Relations: Algorithmic workflows and industry applications.
- Practical Failure Cases & Pitfalls: Common software bugs (e.g., coordinate axis swapping in OpenCV, forgetting
optimizer.zero_grad(),SettingWithCopyWarningin Pandas).
2. resource.md (Curated References & Reading Lists)
Generated inside each weekly exercise folder with curated external links:
- Official Documentation: Direct links to PyTorch, NumPy, Pandas, OpenCV, and Gradio guides.
- Visual & Interactive Explanations: 3Blue1Brown animations, CNN Explainer 3D tools, Distill.pub articles, and Stanford CS231n notes.
- Bonus Challenge Prompts: Guidance on optional extension exercises.
3. curriculum_[grade_level].md (Course Syllabus)
Generated in the root output directory to outline the full course schedule:
- Empirical Pipeline Run Metrics: Total images processed, baseline accuracy achieved, and GPU execution time per stage.
- Classroom Case Studies: Direct file paths to sample images that the model classified correctly (true positives) and incorrectly (false positives/negatives) for classroom discussion.
- Dataset Summary: Number of classes, imbalance ratio, size category, and suggested evaluation metrics.
- Weekly Schedule: Complete week-by-week calendar mapping each topic to hands-on coding labs.